<script lang="ts" setup>
import { inject, ref } from 'vue';
import { formProps } from './form';
import { tabPaneRootContextKey, tabsRootContextKey } from '../../../tokens/tabs';
import useStore from '@/store';
defineOptions({ name: 'WindowsForm' });
const props = defineProps(formProps);
const tabPaneRoot = inject(tabPaneRootContextKey);

const maximize = ref(false);
// 最大化
const handleMaximize = () => {
  maximize.value = !maximize.value;
  tabPaneRoot.handleMaximize();
};
//最小化
const handleMinimize = () => {
  tabPaneRoot.handleMinimize();
};
//移除tab
const handleTabRemove = () => {
  tabPaneRoot.handleTabRemove();
};
const pass = license => {
  if (license && useStore.setting.licenses.indexOf(license) == -1) return false;
  return true;
};
</script>
<template>
  <div class="windows-form">
    <div ref="header" class="windows-form__header">
      <div class="windows-form__title">
        <el-image style="width: 20px" :src="tabPaneRoot.props.icon" fit="contain" />
        <span>{{ tabPaneRoot.props.label }}</span>
      </div>
    </div>
    <div class="windows-form__defaulbtn-wrapper">
      <div class="windows-form__defaulbtn" @click="handleMinimize">
        <el-icon><i-fluent-subtract-48-regular /></el-icon>
      </div>
      <div class="windows-form__defaulbtn" @click="handleMaximize">
        <el-icon v-if="maximize"><i-fluent-square-multiple-48-regular /></el-icon>
        <el-icon v-else><i-fluent-square-48-regular /></el-icon>
      </div>
      <div class="windows-form__defaulbtn" @click="handleTabRemove">
        <el-icon>
          <i-fluent-dismiss-48-regular />
        </el-icon>
      </div>
    </div>
    <div class="windows-form__btn-wrapper">
      <div class="windows-form__btn-item" v-for="item in props.buttons" @click="pass(item.license) ? item.fn() : ''" :class="[pass(item.license) ? '' : 'disabled']">
        <el-icon>
          <component :is="item.icon" />
        </el-icon>
        <span v-if="item.name">{{ item.name }}</span>
      </div>
    </div>
    <!-- <div class="windows-form__crumbs-wrapper">
      <el-breadcrumb separator-icon="ArrowRight">
        <el-breadcrumb-item>此系统</el-breadcrumb-item>
        <el-breadcrumb-item>系统中心</el-breadcrumb-item>
        <el-breadcrumb-item>模块管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div> -->
    <div class="windows-form__content">
      <div class="windows-form-container">
        <div class="windows-form-container-content">
          <div class="windows-form-container-content-left">
            <slot name="mainleft"></slot>
          </div>
          <div class="windows-form-container-content-right">
            <el-collapse value="1" accordion v-if="props.showSearcher">
              <el-collapse-item title="展开搜索条件" name="1">
                <slot name="search"></slot>
              </el-collapse-item>
            </el-collapse>
            <slot></slot>
            <div class="windows-form-container-pagination">
              <slot name="pagination"></slot>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss">
.windows-form {
  .el-collapse-item__header {
    padding-left: 5px;
    height: 35px;
    border-bottom: 1px solid #ebeef5;
  }
  .el-collapse-item__content {
    padding: 0px 15px;
    padding-top: 20px;
  }
  .el-form-item {
    padding: 0px 5px;
  }
  .el-select,
  .el-input-number {
    width: 100%;
  }
}
</style>
<style lang="scss" scoped>
.windows-form {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  background: rgba(240, 243, 249, 1);
  border: 1px solid #ccc;
  overflow: hidden;
  //width: 800px;
  .windows-form__header {
    display: flex;
    justify-content: space-between;
    height: 30px;
    user-select: none;
    .windows-form__title {
      display: flex;
      align-items: center;
      font-size: 12px;
      padding: 5px;
      span {
        margin-left: 5px;
      }
    }
  }
  .windows-form__defaulbtn-wrapper {
    position: absolute;
    right: 0;
    top: 0;
    display: flex;
    height: 30px;
    .windows-form__defaulbtn {
      width: 50px;
      display: flex;
      justify-content: center;
      align-items: center;
      &:hover {
        background: #e9e9eb;
      }
      &:last-child {
        border-top-right-radius: 5px;
        &:hover {
          color: #fff;
          background: #c45656;
        }
      }
    }
  }
  .windows-form__btn-wrapper {
    min-height: 50px;
    display: flex;
    align-items: center;
    padding: 0px 10px;
    border-bottom: 1px solid #dcdfe6;
    .windows-form__btn-item {
      padding: 8px 8px;
      margin-right: 15px;
      display: flex;
      border-radius: 5px;
      cursor: pointer;
      align-items: center;
      color: #606266;
      &:not(.disabled):hover {
        background: #e5e5e5;
      }
      > .el-icon {
        font-size: 20px;
      }
      > span {
        font-size: 12px;
        margin-left: 5px;
      }
    }
    .disabled {
      opacity: 0.3;
      cursor: not-allowed;
    }
  }
  .windows-form__crumbs-wrapper {
    .el-breadcrumb {
      box-shadow: 0 0 0 1px var(--el-input-border-color, var(--el-border-color)) inset;
      background: #ffffff;
      padding: 10px;
    }
  }
  .windows-form__content {
    background-color: #fff;
    flex: 1;
    overflow: hidden;
    .windows-form-container {
      height: 100%;
      display: flex;
      flex-direction: column;

      .windows-form-container-content {
        flex: 1;
        display: flex;
        overflow: hidden;
        .windows-form-container-content-left {
          border-right: 1px solid #dcdfe6;
          overflow: auto;
          //padding-top: 10px;
        }
        .windows-form-container-content-right {
          height: 100%;
          flex: 1;
          display: flex;
          flex-direction: column;
          overflow: auto;
        }
      }
    }
  }
}
</style>
